package com.offcn.coder;
/*
InterruptedException（）函数与 interrupt（）函数
 */
public class Test03 {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("target1 is running");
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println("target2 is running");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
        t1.start();
        t2.start();
        /*java.lang.InterruptedException: sleep interrupted
	    at java.lang.Thread.sleep(Native Method)
	    at com.offcn.coder.Test03$1.run(Test03.java:13)
	    at java.lang.Thread.run(Thread.java:748)

         */
       t1.interrupt();
       t2.interrupt();

    }
}
